<template>

    <div class="cont">
        <scroller
            :on-refresh="refresh"
            :on-infinite="infinite"
            ref="infinite"
            class="cont"
        >
            <router-link
                class="list"
                v-for="(item, index) in listSource"
                :key="index"
                :to="{path:'/orderCont',query:{order_id: item.id}}"
            >
                <div>已核销{{item.used_num}}张 / 总计{{item.num}}张</div>
                <div>
                    <img :src="item.images">
                    <div>
                        <div style="-webkit-box-orient: vertical;">{{item.title}}</div>
                        <div style="-webkit-box-orient: vertical;">
                            {{item.desc}}
                        </div>
                        <div>
                            <div>
                                ￥{{item.coupon_fee}}
                            </div>
                        </div>
                    </div>
                </div>
                <div>
                    <span>合计:</span>
                    <span>￥{{item.coupon_fee}}</span>
                </div>
                <div>
                    <span>核销码:</span>
                    <span>{{item.code}}</span>
                </div>
            </router-link>
        </scroller>
    </div>
</template>
<script>

import wxPay from '../../config/wxPay.js';
export default {
    name: "allOrder",
    data() {
        return {
            page: 1,
            limit: 10,
            noData: true,
            listSource: [],
        };
    },
    methods: {
        infinite() {
            this.listData();
        },
        refresh() {
            this.page = 1;
            this.listData(true);
        },
        listData(type) {
            let params = {
                page: this.page,
                limit: this.limit,
            };
            this.$post("/member/get_coupon_list", params)
                .then(res => {
                    if (res.code === 20000) {
                        this.page++;
                        if (type) {
                            this.listSource = res.data.list;
                            setTimeout(() => {
                                this.$refs.infinite.finishPullToRefresh();
                            }, 500);
                        } else {
                            for (let i in res.data.list) {
                                let newData = res.data.list[i];
                                this.listSource.push(newData);
                            }
                            console.log(res.data.list.length < this.limit);
                            if (res.data.list.length < this.limit) {
                                this.noData = false;
                                this.$refs.infinite.finishInfinite(true);
                            } else {
                                this.$refs.infinite.finishInfinite();
                            }
                        }
                    }
                })
                .catch(err => { });
        },
    },
    beforeCreate() {
        document.querySelector("body").setAttribute("style", "background-color:#e1deff");
    },
    created() {
        // 实例创建完成
        // this.infoData();
    },
};
</script>
<style lang="less" scoped>
@import url("../../asset/css/allOrder");
</style>